﻿using System;

namespace OpusSuite.Models.Lib
{
    [Serializable]
    public class ModelException : Exception
    {
        private readonly string _message;
        private readonly string _innerMessage;

        public ModelException(string message, Exception e)
        {
            _message = message;

            if (e != null)
            {
                _innerMessage = e.Message;

                // append the innermost message
                Exception f = e;
                while (f.InnerException != null)
                {
                    f = f.InnerException;
                    if (!string.IsNullOrWhiteSpace(f.Message))
                        _innerMessage = f.Message;
                }
            }
        }

        public override string Message
        {
            get
            {
                { return string.Format("{0}{1}", _message, _innerMessage);}
            }
        }
    }
}
